package com.chaodriod.common.system;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

/**
 * Created by annam on 2018/3/20.
 */

public class BatteryReceiver extends BroadcastReceiver {

    public BatteryReceiver() {
        super();
    }

    private BatteryCallback mBatteryCallback;

    public BatteryReceiver(BatteryCallback batteryCallback) {
        mBatteryCallback = batteryCallback;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        int level = intent.getIntExtra("level", 0);
        mBatteryCallback.onBatteryLevel(level);
    }

    public IntentFilter getIntentFilter() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
        return intentFilter;
    }

    public interface BatteryCallback {
        void onBatteryLevel(int level);
    }
}
